package com.fyl.pattern.interpreter;

/**
 * 加法表达式类
 */
public class Plus extends AbstractExpression {
    //运算符左边的表达式
    private AbstractExpression left;
    //运算符右边的表达式
    private AbstractExpression right;

    public Plus(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }

    @Override
    public int interpret(Context context) {
        //将左边表达式的结果和右边表达式的结果相加
       return left.interpret(context)+right.interpret(context);

    }

    @Override
    public String toString() {
        return "("+left.toString()+"+"+right.toString()+")";
    }
}
